package com.kaifamiao.wendao.service;

import com.kaifamiao.wendao.dao.CommentDao;
import com.kaifamiao.wendao.entity.Comment;
import com.kaifamiao.wendao.entity.Topic;

import java.time.LocalDateTime;
import java.util.List;

public class CommentService {

    private CommentDao cd = new CommentDao();

    /**
     * 查询指定话题的所有评论
     * @param t 待查询评论信息的话题对象
     * @return 返回指定话题的所有评论信息
     */
    public List<Comment> load( Topic t ){
        return cd.findByTopicId( t.getId() );
    }

    public boolean save( Comment c ) {
        // 设置主键值
        c.setId( cd.nextId() );
        // 设置评论时间
        c.setPublishTime( LocalDateTime.now() );
        return cd.save( c );
    }

}
